public class ThreadDemo {
    static int  count = 0;

    public static void main(String[] args) throws InterruptedException {
        Object locker1 = new Object();
        Object locker2 = new Object();
        Thread t3 = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                while(count%3==0){
                    System.out.println(Thread.currentThread().getName());
                }
            }
        },"c");
        Thread t2 = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                while(count%3==1){
                    try {
                        t3.join();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName());
                }
            }
        },"b");
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 10; i++) {
                try {

                    t2.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName());
            }
        },"a");


        t1.start();
        t2.start();
        t3.start();

    }
}
